#include "Food.h"
#include <time.h>
#include "../Framework/Include/WinApp.h"
//--------------------------------------------------
Food::Food(void)
:m_pFood(NULL),mPosX(1000.0f), mPosY(0.0f), mWidth(0), mHeight(0), mStartPosX(0), mStartPosY(0)
{	
	speed = 100.0f;
	m_pFood = NULL;
	mAlive = true;
	mRandPosY = 0;
	HackedPosY = 0.0f;
	mIsVisible = false;
	mVisibility = 0;
}

//--------------------------------------------------
Food::~Food( void )
{
	
}

//--------------------------------------------------
void Food::Render(HDC bbDC, HDC spriteDC, int isVisible)
{	
	if(mVisibility == 0 || mVisibility == 1)
	m_pFood->Render( bbDC, spriteDC, mPosX, mPosY );
}

//--------------------------------------------------
void Food::Update(RECT Collider, float dt, int Visible)
{
	if(Visible == 0)
	{
		return;
	}

	FoodRect.left = (LONG)(mPosX);
	FoodRect.top = (LONG)(mPosY);
	FoodRect.right = mPosX + m_pFood->GetWidth();
	FoodRect.bottom =  mPosY + m_pFood->GetHeight();
	

	if(RectRectCollisionCheck( Collider,FoodRect) )
	{
		if(mVisibility == 0)
		{
			mVisibility = 1;
		}
	}
	else
	{
		if(mVisibility == 2)
		{
			mPosX = HackedPosX;
			mPosY = HackedPosY;
			mVisibility = 0;
		}
	    if(mVisibility == 1)
		{
			mVisibility = 0;
		}
	}
		
	if(mPosY >=600)
	{
		mPosX = HackedPosX;
		mPosY = HackedPosY;
		mVisibility = 0;
	}

	mPosY += speed*dt;
	
	
	
}
//---------------------------------------------------
RECT Food::GetCurrentRect()
{
	return FoodRect;
}

//------------------------------------------------
void Food::Load(Bitmap *FoodBitmap)
{
	m_pFood =  FoodBitmap;	
}